﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Domain.DTO;
using Warehouse.Read.API.Applcation.Command.ChartWarehouseCommand;
using Warehouse.Read.API.Applcation.Command.InjureCommand;
using Warehouse.Read.API.Dtos;

namespace Warehouse.Read.API.Controllers
{
    /// <summary>
    /// 图表
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class ChartController : ControllerBase
    {

        IMediator mediator;

        public ChartController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 显示入库的图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ChartDto>>> GetStorageList()
        {
            Dtos.ApiResult<List<ChartDto>> result = new Dtos.ApiResult<List<ChartDto>>();

            try
            {
                result.Data = await mediator.Send(new ChartStorageCommand());
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 显示出库的图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ChartDto>>> GetOutboundList()
        {
            Dtos.ApiResult<List<ChartDto>> result = new Dtos.ApiResult<List<ChartDto>>();

            try
            {
                result.Data = await mediator.Send(new ChartOutboundCommand());
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 显示盘点的图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ChartDto>>> GetInventoryList()
        {
            Dtos.ApiResult<List<ChartDto>> result = new Dtos.ApiResult<List<ChartDto>>();

            try
            {
                result.Data = await mediator.Send(new ChartInventoryCommand());
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 显示调拨的图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ChartDto>>> GetAllocateList()
        {
            Dtos.ApiResult<List<ChartDto>> result = new Dtos.ApiResult<List<ChartDto>>();

            try
            {
                result.Data = await mediator.Send(new ChartAllocateCommand());
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }


    }
}
